package com.example.wto.viewpagertest01;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wto on 4/14/2017.
 */

public class Teacher implements ConvertToJsonObject
{
    private List<DayOfWeek> weekList=new ArrayList<DayOfWeek>();;//星期列表
    private TeacherBean bean=null;
    public Teacher()
    {
       
    }

    public Teacher(TeacherBean bean)
	{
		super();
		this.bean = bean;
	}

	public TeacherBean getBean()
	{
		return bean;
	}

	public void setBean(TeacherBean bean)
	{
		this.bean = bean;
	}

	public List<DayOfWeek> getWeekList()
    {
        return weekList;
    }

    public void setWeekList(List<DayOfWeek> weekList)
    {
        this.weekList = weekList;
    }

    @Override
    public String toJsonObject()
    {
        JSONObject jsonObject=new JSONObject();
        JSONArray jsonArray=new JSONArray();
        try
        {
            jsonObject.put("college_id",bean.getCollege_id());
            jsonObject.put("college_name",bean.getCollge_name());
            jsonObject.put("s_id",bean.getS_id());
            jsonObject.put("s_name",bean.getS_name());
            jsonObject.put("teacher_id",bean.getTeacherID());
            jsonObject.put("teacher_name",bean.getTeacherName());
            DayOfWeek weekDay=null;
            for(int i=0;i<weekList.size();i++)
            {
                weekDay=weekList.get(i);
                JSONObject jso=new JSONObject();
                jso.put("weekName",weekDay.getWeekName());
                JSONArray jsonArrayCourse = new JSONArray();
                List<Course> courseList=weekDay.getCourseList();
                for(int j=0;j<courseList.size();j++)
                {
                	jsonArrayCourse.put(courseList.get(j).getCourseName());
                }
                jso.put("course", jsonArrayCourse);
                jsonArray.put(jso);
            }
            jsonObject.put("courses",jsonArray);
        } catch (JSONException e)
        {
            e.printStackTrace();
        }
        return jsonObject.toString();
    }
}
